const name = "Order"
const lowerName = "order"
const fs = require('fs')
// 模板地址
const controller_temp_path = __dirname+"/template/template.controller.txt"
const route_temp_path = __dirname+"/template/template.route.txt"
const services_temp_path = __dirname+"/template/template.service.txt"


// 生成的文件路径
const controller_new_path = __dirname+`/newFile/${lowerName}.controller.js`
const route_new_path = __dirname+`/newFile/${lowerName}.route.js`
const services_new_path = __dirname+`/newFile/${lowerName}.service.js`



const mysql = require('mysql');
const conn = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'q48701866',
    database: 'crowdfunding',
    port: 3306
});
conn.connect();


const creatController = () => {
    const res = fs.readFileSync(controller_temp_path, 'utf-8')
    const fileInfo = res.replaceAll('${name}', name).replaceAll('${lowerName}', lowerName)
    fs.writeFileSync(controller_new_path, fileInfo)
    console.log("创建controller文件成功")
}
const creatRoute = () => {
    const res = fs.readFileSync(route_temp_path, 'utf-8')
    const fileInfo = res.replaceAll('${name}', name).replaceAll('${lowerName}', lowerName)
    fs.writeFileSync(route_new_path, fileInfo)
    console.log("创建route文件成功")
}
const creatServices = () => {
    const res = fs.readFileSync(services_temp_path, 'utf-8')
    const fileInfo = res.replaceAll('${name}', name).replaceAll('${lowerName}', lowerName)
    fs.writeFileSync(services_new_path, fileInfo)
    console.log("创建services文件成功")
}

creatController()
creatRoute()
creatServices()

